﻿#include <iostream>
//服装抽象类
class Clothing
{
public:
    virtual void show() = 0;
    virtual ~Clothing() {}
};
//衣服种类1
class Cloes :public Clothing
{
    void show()
    {
        std::cout << "I'm cloes!" << std::endl;
    }
};
//衣服种类二
class Coat :public Clothing
{
    void show()
    {
        std::cout << "I'm coat!" << std::endl;
    }
};

//总服装厂
class Factory
{
public:
    virtual Clothing* creatfactory() = 0;
    virtual ~Factory() {}
};
//衣服种类一生产链
class ShoesFactory :public Factory
{
public:
    Clothing* creatfactory()
    {
        return new Cloes;
    }
};
//衣服种类二生产链
class CoatFactory :public Factory
{
public:
    Clothing* creatfactory()
    {
        return new Coat;
    }
};


int main()
{
    //生产衣服种类一流程
    Factory* shoes_factory = new ShoesFactory();//服装厂开设衣服种类一的生产线
    Clothing* m_shoes = shoes_factory->creatfactory();//衣服种类一生产线产出服装
    if (m_shoes)
    {
        m_shoes->show();
        //释放资源
        delete m_shoes;
        m_shoes = NULL;
    }
    //生产衣服种类二流程
    Factory* coat_factory = new CoatFactory();//服装厂开设衣服种类二的生产线
    Clothing* m_coat = coat_factory->creatfactory();//衣服种类二生产线产出服装
    if (m_coat)
    {
        m_coat->show();
        //释放资源
        delete m_coat;
        m_coat = NULL;
    }
}
